<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>首页</title>
    <style>
        /* 整体页面布局 */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f4;
        }
        /* 导航栏样式 */
        nav {
            background-color: #333;
            overflow: hidden;
        }
        nav a {
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }
        nav a:hover {
            background-color: #ddd;
            color: black;
        }
        /* 表单样式 */
        form {
            background-color: #fff;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
        }
        label {
            margin-right: 10px;
        }
        input[type="text"] {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 3px;
        }
        input[type="submit"] {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #45a049;
        }
        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        th, td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
        /* 操作列样式 */
        td a {
            display: inline-block;
            padding: 6px 12px;
            background-color: #007BFF;
            color: white;
            text-decoration: none;
            border-radius: 3px;
        }
        td a:hover {
            background-color: #0056b3;
        }
        /* 不可操作状态的样式 */
        td span.disabled {
            display: inline-block;
            padding: 6px 12px;
            background-color: #555555;
            color: white;
            border-radius: 3px;
            cursor: not-allowed;
        }
    </style>
<%--    <script src="https://code.jquery.com/jquery-1.4.4.min.js"></script>--%>
    <!-- 或者使用最新的 jQuery 版本 -->
    <script src="${pageContext.request.contextPath}/js/jquery-3.7.1.min.js"></script>
    <script>
        function showRejectDialog(reservationId,classroomId) {
            const rejectReason = prompt("请输入不通过的原因：");
            if (rejectReason) {
                $.ajax({
                    type: "POST",
                    url: "/admin/rejectReservation",
                    data: {
                        reservationId: reservationId,
                        classroomId:classroomId,
                        rejectReason: rejectReason
                    },
                    success: function() {
                        // 刷新页面或更新预约信息列表
                        location.reload();
                    },
                    error: function() {
                        alert("请求失败，请稍后重试。");
                    }
                });
            }
        }
    </script>
</head>
<body>
<nav>
    <a href="login.jsp">首页</a>
    <a href="logoutServlet">退出登录</a>
</nav>
<h2>用户预约信息</h2>
<table border="1px">
    <tr>
        <th>用户姓名</th>
        <th>教室名称</th>
        <th>开始时间</th>
        <th>结束时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    <c:forEach var="reservation" items="${reservationList}">
        <tr>
            <td>${reservation.user.username}</td>
            <td>${reservation.classroom.classroomName}</td>
            <td><fmt:formatDate value="${reservation.startDatetime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td><fmt:formatDate value="${reservation.endDatetime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td>${reservation.status}</td>
            <td>
                <a href="/admin/approveReservation?reservationId=${reservation.reservationId}&classroomId=${reservationList.classroom.classroomId}">同意</a>
                <a href="#" onclick="showRejectDialog(${reservation.reservationId},${reservationList.classroom.classroomId})">不同意</a>
            </td>
        </tr>
    </c:forEach>
</table>
</body>
</html>